<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>

<body>
    <div id="container"></div>
    <script>
    var Factory = function(type, content) {
        if (this instanceof Factory) {
            console.log(this[type]);
            var s = new this[type](content);
            return s;
        } else {
            return new Factory(type, content);
        }
    }
    Factory.prototype = {
        Java: function(content) {},
        JavaScript: function(content) {},
        UI: function(content) {
            this.content = content;
            (function() {
                var div = document.createElement('div');
                div.innerHTML = content;
                div.style.border = '1px solid red';
                document.getElementById('container').appendChild(div);
            })(content)
        }
    }
    // 调用
    var obj = Factory('UI', 'UI真的棒');
    console.dir(obj);
    </script>
</body>

</html>